(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.append(0)
days = 0
candies = 0
while days < n:
if a[days] <= 8:
candies += a[days]
else:
candies += 8
a[days + 1] += a[days] - 8
days += 1
if candies >= k:
break
if candies < k:
print('-1')
else:
print(days)
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long int
ll binaryToDecimal(string n)
{
string num = n;
int dec_value = 0;
// Initializing base value to 1, i.e 2^0
int base = 1;
int len = num.length();
for (int i = len - 1; i >= 0; i--)
{
if (num[i] == '1')
dec_value += base;
base = base * 2;
}
return dec_value;
}
string DecimalToBinary(ll num)
{
string str;
while (num)
{
if (num & 1) // 1
str += '1';
else // 0
str += '0';
num >>= 1; // Right Shift by 1
}
return str;
}
void solve()
{
ll n,k;
cin>>n>>k;
ll arr[100];
ll sum=0;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
sum+=arr[i];
}
ll count=0;
ll sum2=0;
for(ll i=0;i<n;i++)
{
arr[i]+=sum2;
if(arr[i]>8)
{
k-=8;
sum2=arr[i]-8;
count++;
}
else
{
k-=arr[i];
sum2=0;
count++;
}
if(k<=0)
{
cout<<count<<endl;
return;
}
}
cout<<"-1"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
}
1475E - Advertising Agency | 1345B - Card Constructions |
1077B - Disturbed People | 653A - Bear and Three Balls |
794A - Bank Robbery | 157A - Game Outcome |
3B - Lorry | 1392A - Omkar and Password |
489A - SwapSort | 932A - Palindromic Supersequence |
433A - Kitahara Haruki's Gift | 672A - Summer Camp |
1277A - Happy Birthday Polycarp | 577A - Multiplication Table |
817C - Really Big Numbers | 1355A - Sequence with Digits |
977B - Two-gram | 993A - Two Squares |
1659D - Reverse Sort Sum | 1659A - Red Versus Blue |
1659B - Bit Flipping | 1480B - The Great Hero |
1519B - The Cake Is a Lie | 1659C - Line Empire |
515A - Drazil and Date | 1084B - Kvass and the Fair Nut |
1101A - Minimum Integer | 985D - Sand Fortress |
1279A - New Year Garland | 1279B - Verse For Santa |